package com.oocl.producer.producer;

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.SAXException;

import com.oocl.producer.output.BookXmlOutput;

/**
 * 读取XML文件，并一条一条推入MQ
 * @author GANAB
 *
 */
public class BookProduceAction {
	private SAXParser parsers = null; 
	private BookHandler bookHandler = null;
	
	public BookProduceAction() {
		try {
			parsers = SAXParserFactory.newInstance().newSAXParser();
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
		} catch (SAXException e) {
			e.printStackTrace();
		}
		bookHandler = new BookHandler();
	}
	
	public void pull(){	
		//推送进MQ
		try {
			parsers.parse(new File("books.xml"), bookHandler);
		} catch (SAXException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		BookXmlOutput bookProducer = new BookXmlOutput();
		//存入X条XML数据
		bookProducer.output(100);
		
//		BookProduceAction action = new BookProduceAction();
//		//推进MQ
//		action.pull();
	}
}
